package com.atwisdom.star.dcs.Thread;

import cn.hutool.core.date.DateTime;
import com.atwisdom.star.dcs.service.Impl.RealTimeDayStatServiceImpl;
import com.atwisdom.star.dcs.util.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;


@Component
public class RealTimeInfoDayTread implements Runnable  {

    @Autowired
    private RealTimeDayStatServiceImpl realTimeDayStatService;

    @Value("${das.dayHour}")
    private int dayHour;

    @Override
    public void run() {
        DateTime current = new DateTime();
        while (true) {
            if(current.hour(true) == dayHour){
                System.out.println("按天统计开始啦，我每天只跑一次，尽量不会影响你们工作");
                try {
                    realTimeDayStatService.realTimeDataStat();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                System.out.println("今天的统计结束了，明天"+dayHour+"点重新开始");
                Utils.sleep(60000l * 60 * 2);
            }else{
                Utils.sleep(60000l * 10);
            }
            current = new DateTime();
        }
    }
}
